<?php
include_once("/var/www/html/new/com.inc.php");
include_once("/var/www/html/new/d/class/abc/Member.class.php");
include_once("/var/www/html/new/d/class/abc/PFTCore777.class.php");
include_once("/var/www/html/new/d/class/SimpleExcel.class.php");

if(!isset($_SESSION['sid'])) exit('登陆过期');
$ac = $GLOBALS['_ac'];
$pw = $GLOBALS['_pw'];
$s  = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));

// exit;
// $aid = 108;
// $aid = 7187;
$aid = $_SESSION['sid'];
$distr = PFTCore777::Distributors($aid);

$op = $_REQUEST['op'] ? $_REQUEST["op"] : date("Y-06-01 00:00:00",strtotime("-1 month"));
$ed = $_REQUEST['ed'] ? $_REQUEST["ed"] : date("Y-m-d 23:59:59");

// $op = "2015-01-01 00:00:00";
// $ed = "2015-09-02 23:59:59";

$re = array();
$_note = array();
foreach($distr as $did=>$dname){
	
	$sel="select j.fid,dname,rectime,j.dtype,daction,dmoney,lmoney,opid,memo from pft_member_journal j left join pft_member m on m.id=j.opid where rectime between '$op' and '$ed' and j.dtype in (4,11) and aid in ($aid,0) and j.fid=".$did." order by rectime DESC";

	$GLOBALS['le']->query($sel);
	while($row=$GLOBALS['le']->fetch_assoc()){
		switch($row['dtype']){
			case 0:$row['dreason']="下单";break;
			case 1:$row['dreason']="取消";break;
			case 3:$row['dreason']="账户资金变化";break;
			case 4:
				if($row['daction']=="0"){
					$row['add_t']=$row['dmoney']/100;
					$row['dreason']=$row['opid']==$_SESSION['memberID']?"线下还款/预存":"分销商还款";
				}
				else{
					$row['redu_t']=$row['dmoney']/100;
					$row['dreason']="消费";
				}
				break;
			case 5:$row['dreason']="利润";break;
			case 6:$row['dreason']="提现或转账的资金冻结";break;
			case 7:$row['dreason']="平台使用费";break;
			case 8:$row['dreason']="短信息费";break;
			case 9:$row['dreason']="银行交易手续费";break;
			case 10:$row['dreason']="凭证费";break;
			case 11:
				if($row['daction']=="0"){
					$row['add_c']=$row['dmoney']/100;
				}
				else{
					$row['redu_c']=$row['dmoney']/100;
				}
				$row['dreason']="供应商调整授信额度";
				break;
		}
		if($row['daction']=="0"){
			$row['add']=$row['dmoney']/100;
		}else{
			$row['redu']=$row['dmoney']/100;
		}
		$row['dis_name'] = $dname;
		$_note[]=$row;
	}
}




$Excel = array();
$Excel[0]['date'] = '日期';
$Excel[0]['opid'] = '操作员';
$Excel[0]['reas'] = '操作说明';
$Excel[0]['iadd'] = '增加金额';
$Excel[0]['icut'] = '消费金额';
$Excel[0]['memo'] = '备注信息';
$Excel[0]['dis_name']= '分销商';
$i=1;
foreach($_note as $row){
	$Excel[$i]['date'] = $row['rectime'];
	$Excel[$i]['opid'] = $row['dname'];
	$Excel[$i]['reas'] = $row['dreason'];
	if($row['daction']=="0"){
		$Excel[$i]['iadd'] = $row['dmoney']/100;
		$Excel[$i]['icut'] = '';
	}else{
		$Excel[$i]['iadd'] = '';
		$Excel[$i]['icut'] = $row['dmoney']/100;
		$row['redu_c']=$row['dmoney']/100;
	}
	$Excel[$i]['memo'] = $row['memo'];
	$Excel[$i]['dis_name'] = $row['dis_name'];
	$i++ ;
}
$xls = new SimpleExcel('UTF-8', true,'授信调整');
$xls->addArray($Excel);
$xls->generateXML('授信调整记录');
exit;

